<template>
  <div>
    <el-form ref="ruleForm" :model="isform" :rules="isrules" label-width="100px" class="demo-ruleForm">
      <el-dialog title="收货地址" :visible.sync="isshow" width="50%" :open="inopen">
        <el-form-item label="角色名称" prop="roleName">
          <el-input v-model="isform.roleName " />
        </el-form-item>
        <el-form-item label="角色编码">
          <el-input v-model="isform.roleCode " />
        </el-form-item>
        <el-form-item label="角色描述">
          <el-input v-model="isform.remark " type="textarea" />
        </el-form-item>
        <el-form-item label="选择菜单">
          <div><el-checkbox v-model="unflod" @change="andup">展开/关闭</el-checkbox>
            <el-checkbox v-model="checked" @change="checked1">全选/取消全选</el-checkbox></div>
          <el-tree
            ref="tree"
            :data="menus"
            show-checkbox
            :default-expand-all="unflod"
            node-key="id"
            highlight-current
            :props="defaultProps"
            @check="currentChecked"
          />
        </el-form-item>

        <div slot="footer" class="dialog-footer">
          <el-button @click="">取 消</el-button>
          <el-button type="primary" @click="submitForm('ruleForm')">确 定</el-button>
        </div>
      </el-dialog>
    </el-form>
  </div>
</template>

<script >
export default {

  components: {},
  props: ['isshow', 'isform', 'rules', 'menus', 'andnew', 'valeb'],
  data() {
    return {
      defaultProps: {
        children: 'children',
        label: 'title'
      },
      unflod: false,
      checked: false,
      isrules: {
        roleName: [
          { required: true, message: '请输入活动名称', trigger: 'blur' }
        ] }
    }
  },
  computed: {},

  mounted() {},

  methods: {
    inopen() {
      console.log('11111111111')
    },
    setCheckedNodes() {
      this.$refs.tree.setCheckedNodes(this.valeb)
    },
    checked1() {
      if (this.checked) {
        this.$refs.tree.setCheckedNodes(this.menus)
      } else {
        this.$refs.tree.setCheckedKeys([])
      }
    },
    andup() {
      var nodes = this.$refs.tree.store.nodesMap
      for (var i in nodes) {
        nodes[i].expanded = this.unflod
      }
    },
    currentChecked(nodeObj, SelectedObj) {
      console.log(SelectedObj)
      console.log(SelectedObj.checkedKeys) // 这是选中的节点的key数组
      console.log(SelectedObj.checkedNodes) // 这是选中的节点数组
      this.isform.permissionIds = SelectedObj.checkedKeys
    },
    submitForm(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          alert('是否提交')
          this.$emit('addseve', this.isform)
        } else {
          console.log('error submit!!')
          return false
        }
      })
    }
  }
}

</script>
<style lang="scss" scoped>
</style>
